package com.industrial.premu.service.impl;

import com.industrial.common.security.utils.SecurityUtils;
import com.industrial.premu.domain.PreMuBenefitEvaluation;
import com.industrial.premu.mapper.PreMuGenDocxMapper;
import com.industrial.premu.mapper.PreMuGenTableMapper;
import com.industrial.premu.service.PreMuGenTableService;
import com.industrial.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.util.*;

@Service
public class PreMuGenTableServiceImpl implements PreMuGenTableService {

    @Autowired
    private PreMuGenTableMapper preMuGenTableMapper;

    private PreMuGenDocxMapper preMuGenDocxMapper;

    @Override
    public List<Map<String, Object>> degb() {

        //查询当年的数据,这里说的当年数据是上一年的数据如现在是2024年，这里说的当年数据是2023年的
        PreMuBenefitEvaluation queryParams = new PreMuBenefitEvaluation();
        setQueryParams(queryParams);
        LocalDate localDate = LocalDate.now();
        queryParams.setYears(String.valueOf(localDate.getYear() - 1));
        Map<String,Object> currentYearsResult = preMuGenTableMapper.degb(queryParams);

        if(currentYearsResult == null || currentYearsResult.isEmpty()){
            return new ArrayList<>();
        }

        queryParams.setYears(String.valueOf(localDate.getYear() - 2));
        Map<String,Object> preYearsResult = preMuGenTableMapper.degb(queryParams);



        List<Map<String,Object>> list = new ArrayList<>();

        //亩均税收
//        Map<String,Object> mjssResultMap = new HashMap<>(16);
//        //获取到当前年的税收
//        BigDecimal currentMjss = (BigDecimal)currentYearsResult.get("mjss");
//        mjssResultMap.put("zbName","亩均税收");
//        mjssResultMap.put("currentYear",currentMjss);
//        if(preYearsResult == null || preYearsResult.get("mjss") == null){
//            mjssResultMap.put("preYear","-");
//            mjssResultMap.put("zf","-");
//        }else{
//            BigDecimal preMjss = (BigDecimal)preYearsResult.get("mjss");
//            mjssResultMap.put("preYear",preMjss);
//            if(preMjss.compareTo(BigDecimal.ZERO) == 0){
//                mjssResultMap.put("zf","-");
//            }else{
//                BigDecimal zf = currentMjss.subtract(preMjss).divide(preMjss, 3, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
//                mjssResultMap.put("zf",zf);
//            }
//
//        }
//        list.add(mjssResultMap);

        // 2025 新增收入利润率
        Map<String,Object> srlrlResultMap = new HashMap<>(16);
        //获取到当前年的税收
        BigDecimal currentSrlrl = (BigDecimal)currentYearsResult.get("srlrl");
        srlrlResultMap.put("zbName","收入利润率");
        srlrlResultMap.put("currentYear",currentSrlrl);
        if((localDate.getYear() - 1) == 2024) {
            srlrlResultMap.put("preYear","新增指标暂无数据对比");
            srlrlResultMap.put("zf","-");
        }
        else if(preYearsResult == null || preYearsResult.get("srlrl") == null){
            srlrlResultMap.put("preYear","-");
            srlrlResultMap.put("zf","-");
        }
        else{
            BigDecimal preSrlrl = (BigDecimal)preYearsResult.get("srlrl");
            srlrlResultMap.put("preYear",preSrlrl);
            if(preSrlrl.compareTo(BigDecimal.ZERO) == 0){
                srlrlResultMap.put("zf","-");
            }else{
                BigDecimal zf = currentSrlrl.subtract(preSrlrl).divide(preSrlrl, 3, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                srlrlResultMap.put("zf",zf);
            }
        }
        list.add(srlrlResultMap);



        //亩均销售收入
        Map<String,Object> mjxssrResultMap = new HashMap<>(16);
        //获取到当前年的税收
        BigDecimal currentMjxssr = (BigDecimal)currentYearsResult.get("mjxssr");
        //mjxssrResultMap.put("zbName","亩均销售收入");
        mjxssrResultMap.put("zbName","亩均营业收入");
        mjxssrResultMap.put("currentYear",currentMjxssr);
        if(preYearsResult == null || preYearsResult.get("mjxssr") == null){
            mjxssrResultMap.put("preYear","-");
            mjxssrResultMap.put("zf","-");
        }else{
            BigDecimal preMjxssr = (BigDecimal)preYearsResult.get("mjxssr");
            mjxssrResultMap.put("preYear",preMjxssr);
           if(preMjxssr != null){
               if(preMjxssr.compareTo(BigDecimal.ZERO) == 0){
                   mjxssrResultMap.put("zf","-");
               }else{
                   BigDecimal zf = currentMjxssr.subtract(preMjxssr).divide(preMjxssr, 3, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                   mjxssrResultMap.put("zf",zf);
               }
           }else{
               mjxssrResultMap.put("zf","-");
           }
        }
        list.add(mjxssrResultMap);


        //单位能耗税收
//        Map<String,Object> dwnhssResultMap = new HashMap<>(16);
//        //获取到当前年的税收
//        Object currentDwnhss = currentYearsResult.get("dwnhss");
//        dwnhssResultMap.put("zbName","单位能耗税收");
//        dwnhssResultMap.put("currentYear",currentDwnhss);
//        if(preYearsResult == null || preYearsResult.get("dwnhss") == null){
//            dwnhssResultMap.put("preYear","-");
//            dwnhssResultMap.put("zf","-");
//        }else{
//            Object preDwnhss = preYearsResult.get("dwnhss");
//
//            BigDecimal currentDwnhssBigDecimal = null;
//            if(currentDwnhss instanceof BigDecimal){
//                currentDwnhssBigDecimal = (BigDecimal) currentDwnhss;
//            }else{
//                Double p = (Double)currentDwnhss;
//                currentDwnhssBigDecimal = new BigDecimal(p);
//            }
//
//            BigDecimal preDwnhssBigDecimal = null;
//
//            if(preDwnhss instanceof BigDecimal){
//                preDwnhssBigDecimal = (BigDecimal) preDwnhss;
//            }else{
//                Double p = (Double) preDwnhss;
//                preDwnhssBigDecimal = BigDecimal.valueOf(p);
//            }
//
//            dwnhssResultMap.put("preYear",preDwnhss);
//            if(preDwnhssBigDecimal.compareTo(BigDecimal.ZERO) == 0){
//                dwnhssResultMap.put("zf","-");
//            }else{
//                BigDecimal zf = currentDwnhssBigDecimal.subtract(preDwnhssBigDecimal).divide(preDwnhssBigDecimal, 3, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
//                dwnhssResultMap.put("zf",zf);
//            }
//
//        }
//        list.add(dwnhssResultMap);

        //单位能耗销售收入
        Map<String,Object> dwnhxssrResultMap = new HashMap<>(16);
        Object currentDwnhxssr = currentYearsResult.get("dwnhxssr");
        //dwnhxssrResultMap.put("zbName","单位能耗销售收入");
        dwnhxssrResultMap.put("zbName","单位能耗营业收入");
        dwnhxssrResultMap.put("currentYear",currentDwnhxssr);
        if(preYearsResult == null || preYearsResult.get("dwnhxssr") == null){
            dwnhxssrResultMap.put("preYear","-");
            dwnhxssrResultMap.put("zf","-");
        }else{
            Object preDwnhxssr = preYearsResult.get("dwnhxssr");

            BigDecimal currentDwnhxssrBigDecimal = null;
            if(currentDwnhxssr instanceof BigDecimal){
                currentDwnhxssrBigDecimal = (BigDecimal) currentDwnhxssr;
            }else{
                Double p = (Double) currentDwnhxssr;
                currentDwnhxssrBigDecimal = BigDecimal.valueOf(p);
            }

            BigDecimal preDwnhxssrBigDecimal = null;
            if(preDwnhxssr instanceof BigDecimal){
                preDwnhxssrBigDecimal = (BigDecimal) preDwnhxssr;
            }else{
                Double p = (Double) preDwnhxssr;
                preDwnhxssrBigDecimal = BigDecimal.valueOf(p);
            }

            dwnhxssrResultMap.put("preYear",preDwnhxssr);
            if(preDwnhxssrBigDecimal.compareTo(BigDecimal.ZERO)==0){
                dwnhxssrResultMap.put("zf","-");
            }else{
                BigDecimal zf = currentDwnhxssrBigDecimal.subtract(preDwnhxssrBigDecimal).divide(preDwnhxssrBigDecimal, 3, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                dwnhxssrResultMap.put("zf",zf);
            }

        }
        list.add(dwnhxssrResultMap);

        // 2025 新增单位污染物排放营业收入
        Map<String,Object> dwwrwfwyyssResultMap = new HashMap<>(16);
        BigDecimal currentDwwrwpfyysr = (BigDecimal)currentYearsResult.get("dwwrwpfyysr");
        dwwrwfwyyssResultMap.put("zbName","单位污染物排放营业收入");
        dwwrwfwyyssResultMap.put("currentYear",currentDwwrwpfyysr);
        if(preYearsResult == null || preYearsResult.get("dwwrwpfyysr") == null){
            dwwrwfwyyssResultMap.put("preYear","-");
            dwwrwfwyyssResultMap.put("zf","-");
        }else{
            BigDecimal preDwwrwpfyysr = (BigDecimal)preYearsResult.get("dwwrwpfyysr");
            dwwrwfwyyssResultMap.put("preYear",preDwwrwpfyysr);
            if(preDwwrwpfyysr != null){
                if(preDwwrwpfyysr.compareTo(BigDecimal.ZERO) == 0){
                    dwwrwfwyyssResultMap.put("zf","-");
                }else{
                    BigDecimal zf = currentDwwrwpfyysr.subtract(preDwwrwpfyysr).divide(preDwwrwpfyysr, 3, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                    dwwrwfwyyssResultMap.put("zf",zf);
                }
            }else{
                dwwrwfwyyssResultMap.put("zf","-");
            }
        }
        list.add(dwwrwfwyyssResultMap);


        //研发经费投入强度
        Map<String,Object> yfjftrqdResultMap = new HashMap<>(16);
        //获取到当前年的税收
        BigDecimal currentYfjftrqd = (BigDecimal)currentYearsResult.get("yfjftrqd");
        yfjftrqdResultMap.put("zbName","研发经费投入强度");
        yfjftrqdResultMap.put("currentYear",currentYfjftrqd);
        if(preYearsResult == null || preYearsResult.get("yfjftrqd") == null){
            yfjftrqdResultMap.put("preYear","-");
            yfjftrqdResultMap.put("zf","-");
        }else{
            BigDecimal preYfjftrqd = (BigDecimal)preYearsResult.get("yfjftrqd");
            yfjftrqdResultMap.put("preYear",preYfjftrqd);
            BigDecimal zf = currentYfjftrqd.subtract(preYfjftrqd);
            yfjftrqdResultMap.put("zf",zf);
        }
        list.add(yfjftrqdResultMap);


        //全员劳动生产率
        Map<String,Object> qyldsclResultMap = new HashMap<>(16);
        //获取到当前年的税收
        BigDecimal currentQyldscl = (BigDecimal)currentYearsResult.get("qyldscl");

        qyldsclResultMap.put("zbName","全员劳动生产率");
        qyldsclResultMap.put("currentYear",currentQyldscl);
        if(preYearsResult == null || preYearsResult.get("qyldscl") == null){
            qyldsclResultMap.put("preYear","-");
            qyldsclResultMap.put("zf","-");
        }else{
            BigDecimal preYfjftrqd = (BigDecimal)preYearsResult.get("qyldscl");
            qyldsclResultMap.put("preYear",preYfjftrqd);
            if(preYfjftrqd != null){
                if(preYfjftrqd.compareTo(BigDecimal.ZERO) == 0){
                    qyldsclResultMap.put("zf","-");
                }else{
                    BigDecimal zf = currentQyldscl.subtract(preYfjftrqd).divide(preYfjftrqd, 3, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                    qyldsclResultMap.put("zf",zf);
                }
            }else{
                qyldsclResultMap.put("zf","-");
            }
        }
        list.add(qyldsclResultMap);
        return list;
    }

    /**
     * 主要指标情况及数据来源表格
     * @return
     */
    @Override
    public List<Map<String,Object>> sjly() {
        //查询当年的数据,这里说的当年数据是上一年的数据如现在是2024年，这里说的当年数据是2023年的
        PreMuBenefitEvaluation queryParams = new PreMuBenefitEvaluation();
        setQueryParams(queryParams);
        LocalDate localDate = LocalDate.now();
        queryParams.setYears(String.valueOf(localDate.getYear() - 1));
        Map<String,Object> currentYearsResult = preMuGenTableMapper.sjly(queryParams);

        if(currentYearsResult == null ||currentYearsResult.isEmpty()){
            return new ArrayList<>();
        }

        queryParams.setYears(String.valueOf(localDate.getYear() - 2));
        //查询上一年的数据
        Map<String,Object> preYearsResult = preMuGenTableMapper.sjly(queryParams);

        List<Map<String,Object>> list = new ArrayList<>();

        //税收  2025年去掉（展示2024年数据时不再需要税收）
//        Map<String,Object> ssResultMap = new HashMap<>(16);
//        //获取到当前年的税收
//        BigDecimal currentActualTax = (BigDecimal)currentYearsResult.get("actual_tax");
//        currentActualTax = currentActualTax.divide(BigDecimal.valueOf(10000L),2,RoundingMode.HALF_UP);
//        ssResultMap.put("zbName","税收");
//        ssResultMap.put("lybm","税务部门");
//        ssResultMap.put("currentYear",currentActualTax);
//        if(preYearsResult == null || preYearsResult.get("actual_tax") == null){
//            ssResultMap.put("preYear","-");
//            ssResultMap.put("zf","-");
//        }else{
//            BigDecimal preActualTax = (BigDecimal)preYearsResult.get("actual_tax");
//            preActualTax = preActualTax.divide(BigDecimal.valueOf(10000L),2, RoundingMode.HALF_UP);
//            ssResultMap.put("preYear",preActualTax);
//            if(preActualTax.compareTo(BigDecimal.ZERO) == 0){
//                ssResultMap.put("zf","-");
//            }else {
//                BigDecimal zf = currentActualTax.subtract(preActualTax).divide(preActualTax, 3, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
//                ssResultMap.put("zf",zf);
//            }
//
//        }
//        list.add(ssResultMap);

        // 2025年新增---利润总额
        Map<String,Object> lrzeResultMap = new HashMap<>(16);
        BigDecimal currentProfitTotal = (BigDecimal)currentYearsResult.get("profit_total");
        currentProfitTotal = currentProfitTotal.divide(BigDecimal.valueOf(10000L),2,RoundingMode.HALF_UP);
        lrzeResultMap.put("zbName","利润总额");
        lrzeResultMap.put("lybm","税务部门");
        lrzeResultMap.put("currentYear",currentProfitTotal);
        if(preYearsResult == null || preYearsResult.get("profit_total") == null){
            lrzeResultMap.put("preYear","-");
            lrzeResultMap.put("zf","-");
        }else{
            BigDecimal preProfitTotal = (BigDecimal)preYearsResult.get("profit_total");
            preProfitTotal = preProfitTotal.divide(BigDecimal.valueOf(10000L),2, RoundingMode.HALF_UP);
            lrzeResultMap.put("preYear",preProfitTotal);
            if(preProfitTotal.compareTo(BigDecimal.ZERO) == 0){
                lrzeResultMap.put("zf","-");
            }else {
                BigDecimal zf = preProfitTotal.subtract(preProfitTotal).divide(preProfitTotal, 3, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                lrzeResultMap.put("zf",zf);
            }

        }
        list.add(lrzeResultMap);


        //总能耗
        Map<String,Object> znhResultMap = new HashMap<>(16);
        //获取到当前年的税收
        Object currentTotalUsed = currentYearsResult.get("total_used");

        if(currentTotalUsed instanceof BigDecimal){
            BigDecimal currentTotalUsedBig = ((BigDecimal) currentTotalUsed).divide(BigDecimal.valueOf(100000000L), 2, RoundingMode.HALF_UP);
            znhResultMap.put("currentYear",currentTotalUsedBig);
        }

        znhResultMap.put("zbName","总能耗");
        znhResultMap.put("lybm","统计或发改部门");
        if(!znhResultMap.containsKey("currentYear")){
            znhResultMap.put("currentYear",currentTotalUsed);
        }
        if(preYearsResult == null || preYearsResult.get("total_used") == null){
            znhResultMap.put("preYear","-");
            znhResultMap.put("zf","-");
        }else{
            Object preTotalUsed = preYearsResult.get("total_used");

            BigDecimal preTotalUsedBigDecimal =null;
            if(preTotalUsed instanceof BigDecimal){
                preTotalUsedBigDecimal = (BigDecimal) preTotalUsed;
                preTotalUsedBigDecimal = preTotalUsedBigDecimal.divide(BigDecimal.valueOf(100000000L),2,RoundingMode.HALF_UP);
            }else{
                Double p = (Double) preTotalUsed;
                preTotalUsedBigDecimal = BigDecimal.valueOf(p);
                preTotalUsedBigDecimal = preTotalUsedBigDecimal.divide(BigDecimal.valueOf(100000000L),2,RoundingMode.HALF_UP);
            }

            if(preTotalUsedBigDecimal.compareTo(BigDecimal.ZERO) == 0){
                znhResultMap.put("preYear","-");
                znhResultMap.put("zf","-");
            }else{

                znhResultMap.put("preYear",preTotalUsedBigDecimal);

                BigDecimal currentTotalUsedBigDecimal = null;
                if(currentTotalUsed instanceof BigDecimal){
                    currentTotalUsedBigDecimal =  ((BigDecimal) currentTotalUsed).divide(BigDecimal.valueOf(100000000L),2,RoundingMode.HALF_UP);
                }else{
                    Double p = (Double) currentTotalUsed;
                    currentTotalUsedBigDecimal=  BigDecimal.valueOf(p);
                    currentTotalUsedBigDecimal = currentTotalUsedBigDecimal.divide(BigDecimal.valueOf(100000000L),2,RoundingMode.HALF_UP);
                }
                BigDecimal zf = currentTotalUsedBigDecimal.subtract(preTotalUsedBigDecimal).divide(preTotalUsedBigDecimal, 3, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                znhResultMap.put("zf",zf);
            }

        }
        list.add(znhResultMap);


        //销售收入
        Map<String,Object> xssrResultMap = new HashMap<>(16);
        //获取到当前年的税收
        BigDecimal currentMainIncome = (BigDecimal)currentYearsResult.get("main_income");
        if(currentMainIncome.compareTo(BigDecimal.ZERO) != 0){
            currentMainIncome = currentMainIncome.divide(BigDecimal.valueOf(10000L),2, RoundingMode.HALF_UP);
        }
        xssrResultMap.put("zbName","销售收入");
        xssrResultMap.put("lybm","税务部门");
        xssrResultMap.put("currentYear",currentMainIncome);
        if(preYearsResult == null || preYearsResult.get("main_income") == null){
            xssrResultMap.put("preYear","-");
            xssrResultMap.put("zf","-");
        }else{
            BigDecimal preMainIncome = (BigDecimal)preYearsResult.get("main_income");
            if(preMainIncome.compareTo(BigDecimal.ZERO) == 0){
                xssrResultMap.put("preYear","-");
                xssrResultMap.put("zf","-");
            }else{
                preMainIncome = preMainIncome.divide(BigDecimal.valueOf(10000L),2, RoundingMode.HALF_UP);
                xssrResultMap.put("preYear",preMainIncome);
                BigDecimal zf = currentMainIncome.subtract(preMainIncome).divide(preMainIncome, 3, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                xssrResultMap.put("zf",zf);
            }

        }
        list.add(xssrResultMap);


        //研发经费支出
        Map<String,Object> yfjfzcResultMap = new HashMap<>(16);
        //获取到当前年的税收
        BigDecimal currentRdFunds = (BigDecimal)currentYearsResult.get("rd_funds");
        if(currentRdFunds.compareTo(BigDecimal.ZERO) != 0){
            currentRdFunds = currentRdFunds.divide(BigDecimal.valueOf(10000L),2, RoundingMode.HALF_UP);
        }
        yfjfzcResultMap.put("zbName","研发经费支出");
        yfjfzcResultMap.put("lybm","税务部门");
        yfjfzcResultMap.put("currentYear",currentRdFunds);
        if(preYearsResult == null || preYearsResult.get("rd_funds") == null){
            yfjfzcResultMap.put("preYear","-");
            yfjfzcResultMap.put("zf","-");
        }else{
            BigDecimal preRdFunds = (BigDecimal)preYearsResult.get("rd_funds");
            if(preRdFunds.compareTo(BigDecimal.ZERO) == 0){
                yfjfzcResultMap.put("preYear","-");
                yfjfzcResultMap.put("zf","-");
            }else{
                preRdFunds = preRdFunds.divide(BigDecimal.valueOf(10000L),2, RoundingMode.HALF_UP);
                yfjfzcResultMap.put("preYear",preRdFunds);
                BigDecimal zf = currentRdFunds.subtract(preRdFunds).divide(preRdFunds, 3, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                yfjfzcResultMap.put("zf",zf);
            }
        }
        list.add(yfjfzcResultMap);


        //年平均职工人数
        Map<String,Object> npjzgrsResultMap = new HashMap<>(16);
        //获取到当前年的税收
        BigDecimal currentAnnualEmployees = (BigDecimal)currentYearsResult.get("annual_employees");
        if(currentAnnualEmployees.compareTo(BigDecimal.ZERO) != 0){
            currentAnnualEmployees = currentAnnualEmployees.divide(BigDecimal.valueOf(10000L),2, RoundingMode.HALF_UP);
        }
        npjzgrsResultMap.put("zbName","年平均职工人数");
        npjzgrsResultMap.put("lybm","人社或统计部门");
        npjzgrsResultMap.put("currentYear",currentAnnualEmployees);
        if(preYearsResult == null || preYearsResult.get("annual_employees") == null){
            npjzgrsResultMap.put("preYear","-");
            npjzgrsResultMap.put("zf","-");
        }else{
            BigDecimal preAnnualEmployees = (BigDecimal)preYearsResult.get("annual_employees");
            if(preAnnualEmployees.compareTo(BigDecimal.ZERO) == 0){
                npjzgrsResultMap.put("preYear","-");
                npjzgrsResultMap.put("zf","-");
            }else{
                preAnnualEmployees = preAnnualEmployees.divide(BigDecimal.valueOf(10000L),2, RoundingMode.HALF_UP);
                npjzgrsResultMap.put("preYear",preAnnualEmployees);
                BigDecimal zf = currentAnnualEmployees.subtract(preAnnualEmployees).divide(preAnnualEmployees, 3, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                npjzgrsResultMap.put("zf",zf);
            }
        }
        list.add(npjzgrsResultMap);

        //用地面积
        Map<String,Object> ydmjResultMap = new HashMap<>(16);
        //获取到当前年的税收
        BigDecimal currentSumArea = (BigDecimal)currentYearsResult.get("sum_area");
        if(currentSumArea.compareTo(BigDecimal.ZERO) != 0){
            currentSumArea = currentSumArea.divide(BigDecimal.valueOf(10000L),2, RoundingMode.HALF_UP);
        }
        ydmjResultMap.put("zbName","用地面积");
        ydmjResultMap.put("lybm","自然资源部门");
        ydmjResultMap.put("currentYear",currentSumArea);
        if(preYearsResult == null || preYearsResult.get("sum_area") == null){
            ydmjResultMap.put("preYear","-");
            ydmjResultMap.put("zf","-");
        }else{
            BigDecimal preSumArea = (BigDecimal)preYearsResult.get("sum_area");
            if(preSumArea.compareTo(BigDecimal.ZERO) == 0){
                ydmjResultMap.put("preYear","-");
                ydmjResultMap.put("zf","-");
            }else{
                preSumArea = preSumArea.divide(BigDecimal.valueOf(10000L),2, RoundingMode.HALF_UP);
                ydmjResultMap.put("preYear",preSumArea);
                BigDecimal zf = currentSumArea.subtract(preSumArea).divide(preSumArea, 3, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                ydmjResultMap.put("zf",zf);
            }
        }
        list.add(ydmjResultMap);


        //污染物排放
        Map<String,Object> wrwpfResultMap = new HashMap<>(16);
        //获取到当前年的税收
        Object currentTotalEquivalent = currentYearsResult.get("total_equivalent");

        if(currentTotalEquivalent != null && currentTotalEquivalent instanceof BigDecimal){
            BigDecimal currentTotalEquivalentBigDecimal = (BigDecimal)currentTotalEquivalent;
            currentTotalEquivalentBigDecimal = currentTotalEquivalentBigDecimal.divide(BigDecimal.valueOf(10000L),2, RoundingMode.HALF_UP);
            wrwpfResultMap.put("currentYear",currentTotalEquivalentBigDecimal);
        }

        wrwpfResultMap.put("zbName","污染物排放");
        wrwpfResultMap.put("lybm","生态环境部门");
        if(!wrwpfResultMap.containsKey("currentYear")){
            wrwpfResultMap.put("currentYear",currentTotalEquivalent);
        }

        if(preYearsResult == null || preYearsResult.get("total_equivalent") == null){
            wrwpfResultMap.put("preYear","-");
            wrwpfResultMap.put("zf","-");
        }else{
            Object preTotalEquivalent = preYearsResult.get("total_equivalent");

            BigDecimal currentTotalEquivalentBigDecimal = null;

            if(currentTotalEquivalent instanceof BigDecimal){
                currentTotalEquivalentBigDecimal = (BigDecimal) currentTotalEquivalent;
                currentTotalEquivalentBigDecimal = currentTotalEquivalentBigDecimal.divide(BigDecimal.valueOf(10000L),2, RoundingMode.HALF_UP);
            }else{
                Double p = (Double) currentTotalEquivalent;
                currentTotalEquivalentBigDecimal = BigDecimal.valueOf(p);
                currentTotalEquivalentBigDecimal = currentTotalEquivalentBigDecimal.divide(BigDecimal.valueOf(10000L),2, RoundingMode.HALF_UP);
            }

            BigDecimal preTotalEquivalentBigDecimal = null;
            if(preTotalEquivalent instanceof BigDecimal){
                preTotalEquivalentBigDecimal = (BigDecimal) preTotalEquivalent;
            }else{
                Double p = (Double) preTotalEquivalent;
                preTotalEquivalentBigDecimal = BigDecimal.valueOf(p);
            }

            if(preTotalEquivalentBigDecimal.compareTo(BigDecimal.ZERO) == 0){
                wrwpfResultMap.put("preYear","-");
                wrwpfResultMap.put("zf","-");
            }else{
                preTotalEquivalentBigDecimal = preTotalEquivalentBigDecimal.divide(BigDecimal.valueOf(10000L),2, RoundingMode.HALF_UP);
                wrwpfResultMap.put("preYear",preTotalEquivalentBigDecimal);
                BigDecimal zf = currentTotalEquivalentBigDecimal.subtract(preTotalEquivalentBigDecimal).divide(preTotalEquivalentBigDecimal, 3, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
                wrwpfResultMap.put("zf",zf);
            }
        }
        list.add(wrwpfResultMap);

        return list;
    }

    /**
     * 设置查询参数
     * @param queryParams
     */
    private void setQueryParams(PreMuBenefitEvaluation queryParams){
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Set<String> roles= loginUser.getRoles();
        if(roles.contains("x_01_011")||roles.contains("along_yellow_river")){
            String county=  loginUser.getSysUser().getDistrict();
            queryParams.setCounty(county);
        }else if(roles.contains("s_01_011")){
            String city=  loginUser.getSysUser().getCity();
            queryParams.setCity(city);
        }else if(roles.contains("p_01_011")){
            String province=  loginUser.getSysUser().getProvince();
            queryParams.setProvince(province);
        }
    }
}
